import { App, FunctionPlugin, ObjectPlugin } from 'vue'
import { useSidebarStore } from '@/store/sidebar.ts'

let permissionPlugin: FunctionPlugin | ObjectPlugin = {
  install: (app: App) => {
    const sidebarStore = useSidebarStore()
    app.directive('permission', {
      //binding 传入绑定值，菜单ID
      mounted(el, binding) {
        if (binding.value && !sidebarStore.menuIds?.includes(String(binding.value))) {
          el['hidden'] = true
        }
      },
    })
  },
}

export default permissionPlugin
